//
// Camera.cpp for Camera in /tmp/noboa-y-global/yn
//
// Made by maxime marie
// Login   <marie_m@epitech.net>
//
// Started on  Fri Apr 20 14:12:58 2012 maxime marie
// Last update Wed May  2 16:33:10 2012 youri noboa
//

#include	"Camera.hh"

Camera::Camera(void)
  : position_(0.0f, 0.0f, 900.0f), rotation_(0.0f, 0.0f, 0.0f)
{
}

void		Camera::initialize(void)
{
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  gluPerspective(70.f, 800.f/600.0f, 1.0f, 10000.0f);
  gluLookAt(position_.x, position_.y, position_.z, rotation_.x, rotation_.y, -1.0f, 0.0f, 1.0f, 0.0f);
  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();
  glEnable(GL_DEPTH_TEST);
  glDepthFunc(GL_LEQUAL);
}

void		Camera::update(const gdl::GameClock &gameClock,
			       gdl::Input &input)
{
  (void)gameClock;
  if (input.isKeyDown(gdl::Keys::A))
    position_.x = position_.x + 100;
  if (input.isKeyDown(gdl::Keys::D))
    position_.x = position_.x - 100;
  if (input.isKeyDown(gdl::Keys::W))
    position_.z = position_.z - 100;
  if (input.isKeyDown(gdl::Keys::S))
    position_.z = position_.z + 100;
  if (input.isKeyDown(gdl::Keys::Q))
    rotation_.x = rotation_.x - 100;
  if (input.isKeyDown(gdl::Keys::E))
    rotation_.x = rotation_.x + 100;
  glMatrixMode(GL_PROJECTION);
  glLoadIdentity();
  gluPerspective(100.f, 800.f/600.0f, 1.0f, 10000.0f);
  gluLookAt(position_.x, position_.y, position_.z, rotation_.x, rotation_.y, -1.0f, 0.0f, 1.0f, 0.0f);
  glMatrixMode(GL_MODELVIEW);
  glLoadIdentity();
}
